<?php
/**
 * Func   十一选五期号创建
 */
defined('IN_YuLin') || exit('NO PERMIT!');

echo '<pre>';
// 获取各类时时彩的的后台设置信息
$lottCateTab  = Table('lottery_category');
$lottTab      = Table('lottery');
$field        = 'lott.id, lott.`title`, lott.`periods`, lott.`sname` as lott_sname';
$sql          = 'SELECT ' . $field . ' FROM ' . $lottCateTab . ' AS cate
                LEFT JOIN ' . $lottTab . ' AS lott
                ON cate.`id` = lott.`cate_id`
                WHERE cate.`sname` = "syxw"';
$syxwList = $db->getall($sql);
if (!$syxwList) {
    echo '彩种信息获取失败！'; 
    return;
}
// 设置彩种补全信息
foreach ($syxwList as $key => $value){
    switch ($value['lott_sname']){
        case 'gd11x5':
            $syxwList[$key]['time_slot']    = array(
                '0' => array('slot'   => '09:00-22:40', 'secont' => 10 * 60, 'nums' => 84),
            );
            break;
        case 'sh11x5':
            $syxwList[$key]['time_slot']    = array(
                '0' => array('slot'   => '08:50-23:40', 'secont' => 10 * 60, 'nums' => 90),
            );
            break;
        case 'sd11x5':
            $syxwList[$key]['time_slot']    = array(
                '0' => array('slot'   => '08:25-22:45', 'secont' => 10 * 60, 'nums' => 87),
            );
            break;
        case 'jx11x5':
            $syxwList[$key]['time_slot']    = array(
                '0' => array('slot'   => '09:00-22:50', 'secont' => 10 * 60, 'nums' => 84),
            );
            break;
//         case 'df11x5':
//             $syxwList[$key]['time_slot']    = array(
//                 '0' => array('slot'   => '09:00-22:50', 'secont' => 10 * 60, 'nums' => 84),
//             );
//             break;
        default:
            break;
    }
}

$table       = table('lottery_k3');
// 一次生成一年的期号，避免进入投注页面找不到期号
$tmpDay  = date('Y-m-d');
for ($di = 1; $di <= 60; $di++){
    $puDay   = date('Y-m-d', strtotime($tmpDay) + 86400);

    // 准备进行当天期号生成
    $baseDayTime = strtotime($tmpDay);
    // 当前时间
    $time        = time();
    foreach ($syxwList as $k => $v){
        if (!$v['time_slot']) continue;
        foreach ($v['time_slot'] as $tk => $tv){
            // 获取期号开始时间与结束时间戳
            $slotData  = explode('-', $tv['slot']);
            $btime     = strtotime($tmpDay . $slotData[0]);
            $etime     = '';
            if ($slotData[1] < $slotData[0]){
                // 第二天
                $etime = strtotime($puDay . $slotData[1]);
            }else{
                $etime = strtotime($tmpDay . $slotData[1]);
            }
            // 检查当天该彩种期号是否生成过
            $check = $db->getrow('SELECT count(id) as cnt FROM ' . $table . ' WHERE tid = ' . $v['id'] . ' AND day = "' . date('Ymd', $btime) . '"');
            if ($check['cnt'] > 0){
                continue;
            }
    
            $period_pre      = date('Ymd', $btime);
            $period_index    = 0;
            // 准备生成期号信息
            $data            = array(
                'tid'        => $v['id'],
                'code'       => '',
                'status'     => '0',
                'createtime' =>$time,
            );
    
            for ($i = 0; $i < $tv['nums']; $i++){
                $period_index++;
                if ($period_index < 10){
                    $period_index = '0' . $period_index;
                }
                $data['starttime'] = $btime;
                $data['stoptime']  = $btime + $tv['secont'];
                $data['period']    = $period_pre . $period_index;
                //             $data['opentime']  = $data['stoptime'] + $tv['secont'];
                $data['day']       = date('Ymd', $btime);
                $btime += $tv['secont'];
                $db->exec('INSERT INTO '.table('lottery_k3').''.CreateInsertSql($data));
            }
        }
    }
    $tmpDay  = $puDay;
}

exit('success');






















